<template>
  <div class="app-container">
    <!--查询-->
    <el-form :inline="true">
      <el-form-item label=" 昵称">
        <el-input
          v-model="searchForm.nickname"
          placeholder=" 昵称"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        />
      </el-form-item>
      <el-form-item label="性别" label-width="60px">
        <el-select
          v-model="searchForm.gender"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        >
          <el-option label="女" value="0" />
          <el-option label="男" value="1" />
          <el-option label="保密" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label=" 联系方式">
        <el-input
          v-model="searchForm.phone"
          placeholder=" 联系方式"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        />
      </el-form-item>
      <el-form-item label=" 工作状态">
        <el-select
          v-model="searchForm.workStatus"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        >
          <el-option label="保密" value="0" />
          <el-option label="工作中" value="1" />
          <el-option label="求职中" value="2" />
          <el-option label="在校生" value="3" />
          <el-option label="摆烂" value="4" />
        </el-select>
      </el-form-item>
      <el-form-item label=" 邮件地址">
        <el-input
          v-model="searchForm.email"
          placeholder=" 邮件地址"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        />
      </el-form-item>
      <el-form-item label="账号状态">
        <el-select
          v-model="searchForm.status"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        >
          <el-option label="正常" value="0" />
          <el-option label="异常" value="1" />
          <el-option label="小黑屋" value="2" />
          <el-option label="锁定" value="3" />
        </el-select>
      </el-form-item>
      <search-buttons
        :fetch-data="fetchList"
        :export-flag="false"
        :add-fun="addUser"
      />
    </el-form>
    <!--表格-->
    <el-table :data="tableData" border stripe>
      <el-table-column type="index" width="50" label="序号" />
      <el-table-column prop="username" label=" 用户名" />
      <el-table-column prop="nickname" label=" 昵称" />
      <el-table-column prop="avatar" label=" 头像地址" width="100">
        <template slot-scope="scope">
          <el-link @click="showAvatar(scope.row.avatar)">查看<i class="el-icon-view el-icon--right" /> </el-link>
          <!--          <img :src="scope.row.avatar">-->
        </template>
      </el-table-column>
      <el-table-column prop="gender" label="性别" width="50">
        <template slot-scope="scope">
          <span v-if="scope.row.gender === 0">女</span>
          <span v-if="scope.row.gender === 1">男</span>
          <span v-if="scope.row.gender === 2">保密</span>
        </template>
      </el-table-column>
      <el-table-column prop="phone" label=" 联系方式" width="120" />
      <el-table-column prop="userInfo" label="个人简介" />
      <el-table-column prop="workStatus" label="工作状态">
        <template slot-scope="scope">
          <span v-if="scope.row.workStatus === 0">保密</span>
          <span v-if="scope.row.workStatus === 1">工作中</span>
          <span v-if="scope.row.workStatus === 2">求职中</span>
          <span v-if="scope.row.workStatus === 3">在校生</span>
          <span v-if="scope.row.workStatus === 4">摆烂</span>
        </template>
      </el-table-column>
      <el-table-column prop="email" label=" 邮件地址" />
      <el-table-column prop="lastLoginTime" label=" 最后登录时间" />
      <el-table-column prop="status" label="账号状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status === 0">正常</span>
          <span v-if="scope.row.status === 1">异常</span>
          <span v-if="scope.row.status === 2">小黑屋</span>
          <span v-if="scope.row.status === 3">锁定</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <operation-buttons
            :del-fun="delSysUserById"
            :detail-fun="userDetail"
            :edit-fun="editUser"
            :row="scope.row"
          />
        </template>
      </el-table-column>
    </el-table>
    <div>
      <!-- 分页 -->
      <pagination
        :page.sync="searchForm.currentPage"
        :total="total"
        :limit.sync="searchForm.pageSize"
        @pagination="fetchList"
      />
    </div>
    <el-dialog
      title="查看头像"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-image :src="avatar" />
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
    </el-dialog>
  </div>
</template>
<script>
import sysUser from '@/api/sysUser'
import Pagination from '@/components/Pagination/index'
import SearchButtons from '@/components/SearchButtons/index'
import OperationButtons from '@/components/OperationButtons/index'
export default {
  components: {
    Pagination,
    SearchButtons,
    OperationButtons
  },
  data() {
    return {
      name: 'SysUser',
      searchForm: {
        currentPage: 1,
        pageSize: 10
      },
      total: 0,
      avatar: '',
      dialogVisible: false,
      tableData: []
    }
  },
  created() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      sysUser.fetchList({ ...this.searchForm }).then(resp => {
        this.tableData = resp.data.data
        this.total = resp.data.total
        this.searchForm.pageNum = resp.data.pageNum
        this.searchForm.currentPage = resp.data.currentPage
      })
    },
    delSysUserById(id) {
      sysUser.delById(id).then(resp => {
        this.$message.info(resp.message)
      })
    },
    clearSearchForm() {
      this.searchForm = {}
    },
    downloadTemplate() {
      window.location.href = 'http://localhost:9527/sysUser/template'
    },
    export2Excel() {
      sysUser.export2Excel({ ...this.searchForm })
    },
    showAvatar(avatar) {
      this.dialogVisible = true
      this.avatar = avatar
    },
    handleClose() {
      this.dialogVisible = false
    },
    addUser() {
      this.$router.push({
        path: '/user/editUser',
        query: {
          type: 0
        }
      })
    },
    editUser(id) {
      this.$router.push({
        path: '/user/editUser',
        query: {
          id,
          type: 1
        }
      })
    },
    userDetail(id) {
      this.$router.push({
        path: '/user/editUser',
        query: {
          id,
          type: 2
        }
      })
    }
  }
}
</script>
<style>

</style>
